package login_refresh;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Create By IntelliJ IDEA
 *
 * @Author: jsonor
 * @Create-Time: 2017/10/9 14:03
 * @Description: 处理用户提交的用户信息（密码和用户名），如果错误，就跳转到error_login_view.html页面
 */
@WebServlet(name = "loginRelocation", urlPatterns = {"/loginRefresh"})
public class LoginRelocationServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req,
      HttpServletResponse resp)
      throws ServletException, IOException {
    // 8.5 提交过来的已经是utf-8的信息
    String name = req.getParameter("name");
    String password = req.getParameter("password");

    if (!name.equals("wch") ||
        !password.equals("1234")) {
      resp.sendRedirect("login-refresh/error_login_view.html");
    } else {
      resp.setHeader("Content-Type", "text/html;charset=utf-8");
      resp.getWriter().println("你成功了！");
    }
  }
}
